package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShopCartService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/user/shoppingCart")
public class ShopCartController {
    @Autowired
    private ShopCartService shopCartService;

    /**
     * 添加当前用户人购物车
     *
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加购物车")
    private Result addShopCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shopCartService.addShopCart(shoppingCartDTO);
        return Result.success();
    }

    /**
     * 查询当前用户人购物车
     */
    @GetMapping("/list")
    @ApiOperation("查询购物车")
    private Result list() {
        List<ShoppingCart> list = shopCartService.list();
        return Result.success(list);
    }

    /**
     * 清空当前用户人购物车
     */
    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    private Result clean() {
        shopCartService.clean();
        return Result.success();
    }

    /**
     * 删除购物车中一个商品
     */
    @PostMapping("/sub")
    @ApiOperation("删除购物车中一个商品")
    private Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shopCartService.sub(shoppingCartDTO);
        return Result.success();
    }
}
